export function generateMonthMap() {
  const months = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec"
  ];
  const monthMap: Record<number, string> = {};

  for (let i = 1; i <= 12; i++) {
    monthMap[i] = months[i - 1];
  }

  return monthMap;
}

export function formatDate(date: string) {
  const { dayjs } = useDayjs();
  const { getLocalLang } = useLocal();
  const locale = getLocalLang();
  // 解析日期
  const d = dayjs(date);
  // 设置语言环境
  d.locale(locale);
  // 获取月份英文简写
  const month = d.format("MMM");
  // 获取日
  const day = d.date();
  // 根据语言环境处理年份
  const year = locale === "th" ? d.year() + 543 : d.year();

  // 拼接为 "1 Feb,2568" 格式
  return `${day} ${month},${year}`;
}

export function formatDateTime(
  date: string | number | Date, // 支持多种日期类型
  pattern = {
    year: "YYYY",
    month: "MM", // 使用英文简写
    day: "DD",
    time: "HH:mm:ss"
  }
) {
  const { dayjs } = useDayjs();
  const { getLocalLang } = useLocal();
  const locale = getLocalLang();

  // 解析日期
  const d = dayjs(date);
  // 设置语言环境
  d.locale(locale);

  // 根据语言环境处理年份
  const year = locale === "th" ? d.year() + 543 : d.year();

  // 格式化各部分
  const formattedYear = d.format(pattern.year);
  const formattedMonth = d.format(pattern.month);
  const formattedDay = d.format(pattern.day);
  const formattedTime = d.format(pattern.time);

  // 返回格式化后的对象
  return {
    year: locale === "th" ? year : formattedYear,
    month: formattedMonth,
    day: formattedDay,
    time: formattedTime,
    fullDate: `${formattedDay} ${formattedMonth},${year} ${formattedTime}`, // 返回完整日期时间字符串
    ymd: `${
      locale === "th" ? year : formattedYear
    }-${formattedMonth}-${formattedDay}`
  };
}

export function getCurYr() {
  const { dayjs } = useDayjs();
  const year = dayjs().format("YYYY");
  const { getLocalLang } = useLocal();
  const locale = getLocalLang();
  return locale === "th" ? parseInt(year) + 543 : year;
}
